
#############################################################################
## $Id: Memory.pm 15615 2013-04-01 21:53:31Z spadkins $
#############################################################################

package App::WorkQueue::Memory;

use App;
use App::WorkQueue;
@ISA = ( "App::WorkQueue" );

use strict;

=head1 NAME

App::WorkQueue::Memory - Interface for a work queue stored in memory

=head1 SYNOPSIS

    use App;

    $context = App->context();
    $q = $context->service("WorkQueue"); 

    ...

=head1 DESCRIPTION

A WorkQueue is for channeling work from a variety of requesting sources to a 
limited set of workers who work the queue.

=cut

sub push {
    &App::sub_entry if ($App::trace);
    my ($self, $entry) = @_;
    if ($self->{type} eq "ARRAY") {
        die "wrong number of columns" if ($#{$self->{columns}} != $#$entry);
    }
    $self->_push_in_mem($entry);
    &App::sub_exit() if ($App::trace);
}

sub acquire {
    &App::sub_entry if ($App::trace);
    my ($self, $sort_spec) = @_;
    my $entry = $self->_acquire_in_mem($sort_spec);
    &App::sub_exit($entry) if ($App::trace);
    return($entry);
}

sub release {
    &App::sub_entry if ($App::trace);
    my ($self, $entry, $columns, $values) = @_;
    $self->_release_in_mem($entry, $columns, $values);
    &App::sub_exit() if ($App::trace);
}

sub unacquire {
    &App::sub_entry if ($App::trace);
    my ($self, $entry) = @_;
    $self->_unacquire_in_mem($entry);
    &App::sub_exit() if ($App::trace);
}

sub locate {
    &App::sub_entry if ($App::trace);
    my ($self, $params, $options) = @_;
    my @entries = $self->_locate_in_mem($params, $options);
    &App::sub_exit(@entries) if ($App::trace);
    return(@entries);
}

sub update {
    &App::sub_entry if ($App::trace);
    my ($self, $entry, $columns, $values) = @_;
    my $nrows = $self->_update_ref($entry, $columns, $values);
    &App::sub_exit($nrows) if ($App::trace);
    return $nrows;
}

sub num_entries {
    &App::sub_entry if ($App::trace);
    my ($self, $status) = @_;
    my $num = $self->_num_entries_in_mem($status);
    &App::sub_exit($num) if ($App::trace);
    return($num);
}

sub count_entries_by_attrib {
    &App::sub_entry if ($App::trace);
    my ($self, $key_attrib, $counts, $count_attrib) = @_;
    $self->_count_entries_by_attrib_in_mem($key_attrib, $counts, $count_attrib);
    &App::sub_exit() if ($App::trace);
}

sub print_entries {
    &App::sub_entry if ($App::trace);
    my ($self, $fh, $format, $columns) = @_;
    $self->_print_entries_in_mem($fh, $format, $columns);
    &App::sub_exit() if ($App::trace);
}

=head1 ACKNOWLEDGEMENTS

 * (c) 2010 Stephen Adkins
 * Author:  Stephen Adkins <spadkins@gmail.com>
 * License: This is free software. It is licensed under the same terms as Perl itself.

=head1 SEE ALSO

L<C<App::Context>|App::Context>,
L<C<App::Service>|App::Service>

=cut

1;

